import socket

tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# 设置超时时间
tcp_socket.settimeout(5)

# 连接到服务器
tcp_socket.connect(("127.0.0.1", 9001))
# 发送数据
tcp_socket.sendall("你好，服务端！".encode(encoding="utf-8"))

# 接收响应
response = tcp_socket.recv(1024)
print("响应：", response.decode(encoding="utf-8"))

# 关闭套接字
tcp_socket.close()
